home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17621 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  91 lines

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Beginner: Some Questions
  5. Date: Tue, 16 Apr 1996 16:10:20 -0400
  6. Organization: Datalytics, Inc.
  7. Message-ID: <3173FEAC.637C@datalytics.com>
  8. References: <N.041596.214427.72@slipper163167.bcs.iafrica.com>
  9. NNTP-Posting-Host: 204.62.224.241
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. herbi@iafrica.com wrote:
  16. > Hi
  17. > I am a C++ beginner. I programmed in T.Pascal, and now i need someting new. The
  18. > basic commands in Pascal is the same as in C++.
  19. > I have some questions, i know how to do it in Pascal,but not in C++. If you
  20. > can, could you perhaps answer them for me.
  21. > 1) How do you repeat a statement for a certen amout of times, or until a key is
  22. > pressed?
  23.  
  24. The first half of this is a C question, the second half is 
  25. OS-specific.  Let me answer the first half.
  26.  
  27. To loop so long as a condition holds true, use while or do loop.  
  28. The former tests before executing the loop code, the latter 
  29. after.  For example,
  30.  
  31. while (x > 25)
  32. {
  33.    // do something here
  34. }
  35.  
  36. or
  37.  
  38. do
  39. {
  40.    // do something here
  41. } while (x > 25);
  42.  
  43. > 2) How do you activate the mouse or mouse driver?
  44.  
  45. This is OS-specific; it isn't a C++ question.
  46.  
  47. > 3) How do you open a text file, input data or read data?
  48.  
  49. The "standard" C++ way to open a file is with the iostreams 
  50. library.  You can write your own C++ class to encapsulate your 
  51. OS's file I/O commands and you can step back to C's STDIO 
  52. functions (like fopen, fread, fclose, etc.).
  53.  
  54. Here's how to open a text file and read a line at a time:
  55.  
  56. #include <fstream.h>        // ifstream
  57.  
  58. void f(void)
  59. {
  60.    ifstream in("filename");
  61.    const int MAX_BUFFER_LENGTH = 80;
  62.    char vBuffer
  63.    [
  64.       MAX_BUFFER_LENGTH
  65.       + 1
  66.    ];
  67.    while (in.getline(
  68.       vBuffer,
  69.       MAX_BUFFER_LENGTH))
  70.    {
  71.       // handle the contents of vBuffer as desired
  72.    }
  73. }
  74.  
  75. > 4) How do you get 256 colors in C++?
  76.  
  77. This is OS and environment (e.g., MS Windows or X Windows) 
  78. specific.
  79.  
  80. > If you know of a site or ftp which have c++ source files or anything to do with
  81. > C++ programming, could you give it to me please.
  82.  
  83. There are many.  Do a yahoo or search.com (or other search 
  84. engine) search for them.
  85.  
  86. -- 
  87. Rob Stewart    | My opinions are generally my own.  They do
  88. Datalytics, Inc.| not necessarily reflect those of my employer.
  89.